package com.tofch.apibacked.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.example.model.entity.InterfaceInfo;
import com.tofch.apibacked.constant.CommonConstant;
import com.tofch.apibacked.model.dto.interfaceInfo.InterfaceInfoQueryRequest;


import com.tofch.apibacked.service.InterfaceInfoService;
import com.tofch.apibacked.mapper.InterfaceInfoMapper;
import com.tofch.apibacked.utils.SqlUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author 31149
* @description 针对表【interface_info(接口信息)】的数据库操作Service实现
* @createDate 2024-03-25 11:27:46
*/
@Service
public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, InterfaceInfo>
    implements InterfaceInfoService{

    @Override
    public QueryWrapper<InterfaceInfo> getQueryWrapper(InterfaceInfoQueryRequest interfaceInfoQueryRequest) {
        QueryWrapper<InterfaceInfo> queryWrapper = new QueryWrapper<>();
        if (interfaceInfoQueryRequest == null) {
            return queryWrapper;
        }

        String sortField = interfaceInfoQueryRequest.getSortField();
        String sortOrder = interfaceInfoQueryRequest.getSortOrder();
//        Long id = interfaceInfoQueryRequest.getId();
        String infoName = interfaceInfoQueryRequest.getInfoName();
        String description = interfaceInfoQueryRequest.getDescription();

        Long userId = interfaceInfoQueryRequest.getUserId();
//        Long infoId = interfaceInfoQueryRequest.getId();
        // 拼接查询条件

        queryWrapper.like(StringUtils.isNotBlank(infoName), "infoName", infoName);
        queryWrapper.like(StringUtils.isNotBlank(description), "description", description);

//        queryWrapper.ne(ObjectUtils.isNotEmpty(infoId), "id", infoId);

//        queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "userId", userId);
        queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
                sortField);
        return queryWrapper;
    }
}




